package com.aurora.source.home.presenter;

import android.content.Context;

import com.aurora.source.base.BaseBean;
import com.aurora.source.base.BasePresenter;
import com.aurora.source.constant.AuroraConstants;
import com.aurora.source.home.bean.NewAreaBean;
import com.aurora.source.home.bean.NewCityBean;
import com.aurora.source.home.bean.NewProvinceBean;
import com.aurora.source.home.view.IAreaSelectView;
import com.aurora.source.util.netutil.SubscriberObserver;

import java.util.List;

/**
 * @author: ww
 * @description:
 * @date: 2018/9/27
 */
public class AreaSelectPresenter extends BasePresenter<IAreaSelectView>{
    public AreaSelectPresenter(IAreaSelectView baseView) {
        super(baseView);
    }

    public void getProvince(Context context){
        requestMethod.getProvince(new SubscriberObserver<BaseBean<List<NewProvinceBean>>>(context, false) {
            @Override
            public void onSuccess(BaseBean<List<NewProvinceBean>> listBaseBean) {
                if(listBaseBean.getCode().equals(AuroraConstants.REQUEST_SUCCESS)){
                    baseView.onGetProvinceSuccess(listBaseBean.getData());
                }else {
                    baseView.onGetProvinceFail(listBaseBean.getMsg());
                }
            }

            @Override
            public void onError(String msg) {
                baseView.onGetProvinceFail(msg);
            }

            @Override
            public void onFinish() {

            }
        });
    }


    public void getCity(Context context,String provinceId){
        requestMethod.getCity(new SubscriberObserver<BaseBean<List<NewCityBean>>>(context, false) {
            @Override
            public void onSuccess(BaseBean<List<NewCityBean>> listBaseBean) {
                if(listBaseBean.getCode().equals(AuroraConstants.REQUEST_SUCCESS)){
                    baseView.onGetCitySuccess(listBaseBean.getData());
                }else {
                    baseView.onGetCityFail(listBaseBean.getMsg());
                }
            }

            @Override
            public void onError(String msg) {
                baseView.onGetCityFail(msg);
            }

            @Override
            public void onFinish() {

            }
        },provinceId);
    }

    public void getArea(Context context,String cityId){
        requestMethod.getArea(new SubscriberObserver<BaseBean<List<NewAreaBean>>>(context, false) {
            @Override
            public void onSuccess(BaseBean<List<NewAreaBean>> listBaseBean) {
                if(listBaseBean.getCode().equals(AuroraConstants.REQUEST_SUCCESS)){
                    baseView.onGetAreaSuccess(listBaseBean.getData());
                }else {
                    baseView.onGetAreaFail(listBaseBean.getMsg());
                }
            }

            @Override
            public void onError(String msg) {
                baseView.onGetAreaFail(msg);
            }

            @Override
            public void onFinish() {

            }
        },cityId);
    }

}
